package com.xiongmm.stream.support;

import java.util.Arrays;
import java.util.List;

/**
 * @author: XiongMM
 * @date: 2019/5/30 17:27
 * @description:
 */
public enum CommandMonitorEnum {

    KEY("del","dump","exists","expire","expireat","keys","migrate","move","object","persist","pexpire","pexpireat","pttl","randomkey","rename","renamenx","sort","type","scan"),
    STRING("append","bitcount","bitop","decr","decrby","get","getbit","getrange","getset","incr","incrby","incrbyfloat","mget","mset","msetnx","psetex","set","setbit","setex","setnx","setrange","strlen"),
    SET("sadd","scard","sdiff","sdiffstore","sinter","sinterstore","sismember","smembers","smove","spop","srandmember","srem","sunion","sunionstore","sscan"),
    ZSET("zadd","zcard","zcount","zincrby","zrange","zrangebyscore","zrank","zrem","zremrangebyrank","zremrangebyscore","zrevrange","zrevrangebyscore","zrevrank","zscore","zunionstore","zinterstore","zscan"),
    HASH("hdel","hexists","hget","hgetall","hincrby","hincrbyfloat","hkeys","hlen","hmget","hmset","hset","hsetnx","hvals","hscan"),
    LIST("blpop","brpop","brpoplpush","lindex","linsert","llen","lpop","lpush","lpushx","lrange","lrem","lset","ltrim","rpop","rpoplpush","rpush","rpushx");

    String[] commands;

    public String[] getCommands() {
        return commands;
    }

    public void setCommands(String[] commands) {
        this.commands = commands;
    }

    CommandMonitorEnum(String... commands) {
        this.setCommands(commands);
    }

    public static CommandMonitorEnum getCommandMonitorEnum(String key){
        for(CommandMonitorEnum monitorEnum : CommandMonitorEnum.values()){
            String[] command = monitorEnum.getCommands();
            List<String> keys = Arrays.asList(command);
            if(keys.contains(key)){
                return monitorEnum;
            }
        }
        return null;
    }
}
